<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   站点城市设置($$)*/

!defined('Q_PATH') && exit;

class SiteController extends AController{

	public function init__(){
		parent::init__();

		if($GLOBALS['___login___']['user_id']!=1){
			$this->E(Q::L('只有用户ID为1的超级管理员才能够访问本页','Controller'));
		}
	}
	
	public function filter_(&$arrMap){
		$arrMap['A.site_domain']=array('like',"%".Q::G('site_domain')."%");
		$arrMap['A.site_name']=array('like',"%".Q::G('site_name')."%");

		$nSiteIshot=Q::G('site_ishot');
		$nSiteIsdefault=Q::G('site_isdefault');
		$nSiteIsindex=Q::G('site_isindex');
		if($nSiteIshot!==null && $nSiteIshot!=''){
			$arrMap['A.site_ishot']=Q::G('site_ishot');
		}
		if($nSiteIsdefault!==null && $nSiteIsdefault!=''){
			$arrMap['A.site_isdefault']=Q::G('site_isdefault');
		}
		if($nSiteIsindex!==null && $nSiteIsindex!=''){
			$arrMap['A.site_isindex']=Q::G('site_isindex');
		}

		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);
	}

	public function bIndex_(){
		if(!Q::G('order_')){
			$this->U('site/index?order_=site_sort&sort_=asc');
		}
	}

	protected function sqljoin_(){
		return "->joinLeft('".Q::C('DB_PREFIX')."district AS B','B.district_name AS province_name','A.province_id=B.district_id')".
			"->joinLeft('".Q::C('DB_PREFIX')."district AS C','C.district_name AS city_name','A.city_id=C.district_id')";
	}


	public function check_domain(){
		$sSiteDomain=trim(Q::G('site_domain'));
		$nId=intval(Q::G('id'));

		if(!$sSiteDomain){
			exit('false');
		}

		// 查询条件
		$arrWhere=array();
		$arrWhere['site_domain']=$sSiteDomain;
		if($nId){
			$arrWhere['site_id']=array('neq',$nId);
		}

		$oSite=SiteModel::F()->where($arrWhere)->setColumns('site_id')->getOne();
		if(empty($oSite['site_id'])){
			exit('true');
		}else{
			exit('false');
		}
	}
	
	public function check_name(){
		$sSiteName=trim(Q::G('site_name'));
		$nId=intval(Q::G('id'));

		if(!$sSiteName){
			exit('false');
		}

		// 查询条件
		$arrWhere=array();
		$arrWhere['site_name']=$sSiteName;
		if($nId){
			$arrWhere['site_id']=array('neq',$nId);
		}

		$oSite=SiteModel::F()->where($arrWhere)->setColumns('site_id')->getOne();
		if(empty($oSite['site_id'])){
			exit('true');
		}else{
			exit('false');
		}
	}

	protected function aInsert($nId=null){
		if(!Q::classExists('Cache_Extend')){
			require_once(Core_Extend::includeFile('function/Cache_Extend'));
		}
		Cache_Extend::updateCache("citysite");
	}

	public function afterInputChangeAjax($sName=null){
		$this->aInsert();
	}

	protected function aUpdate($nId=null){
		$this->aInsert();
	}

	public function aForeverdelete_deep($sId){
		$this->aInsert();
	}

	public function aForeverdelete($sId){
		$this->aInsert();
	}

	protected function aForbid(){
		$this->aInsert();
	}
	
	protected function aResume(){
		$this->aInsert();
	}

}
